package writtenexamination.other;

import java.util.Arrays;
import java.util.HashMap;

/**
 * @author cyt
 * @create 2020-10-28 16:50
 */
public class Ta {
    public static void main(String[] args) {

        HashMap<Object, Object> map = new HashMap<>();
        map.put("d", "d");

        int[] arr = {1, 23, 5, 6, 7, 89, 9};
        Ta ta = new Ta();
        int search = ta.search(arr, 100);
        System.out.println(search);
    }

    public int search(int[] arr, int target) {
        Arrays.sort(arr);
        int low, high;
        int ans = -1;
        low = 0;
        high = arr.length - 1;
        int mid = 0;
        int count = 0;
        while (low <= high) {
            count++;
            mid = low + (high - low) / 2;
            if (arr[mid] == target) {
                ans = arr[mid];
            }
            if (arr[mid] > target) {
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        System.out.println("count - > " + count);
        return ans;
    }
}
